-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix compile-time warnings and other nits #30
Conversation
Hi @jrabinow |
Before$ sudo make clean
$ sudo make 2>&1 | grep "warning"
clang: warning: -framework IOKit: 'linker' input unused [-Wunused-command-line-argument]
smctemp.cc:61:1: warning: 'OSSpinLock' is deprecated: first deprecated in macOS 10.12 - Use os_unfair_lock() from <os/lock.h> instead [-Wdeprecated-declarations]
smctemp.cc:153:3: warning: 'IOMasterPort' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
smctemp.cc:214:3: warning: 'OSSpinLockLock' is deprecated: first deprecated in macOS 10.12 - Use os_unfair_lock_lock() from <os/lock.h> instead [-Wdeprecated-declarations]
smctemp.cc:242:3: warning: 'OSSpinLockUnlock' is deprecated: first deprecated in macOS 10.12 - Use os_unfair_lock_unlock() from <os/lock.h> instead [-Wdeprecated-declarations]
smctemp.cc:326:3: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
smctemp.cc:326:20: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
6 warnings generated.
clang: warning: -framework IOKit: 'linker' input unused [-Wunused-command-line-argument]
smctemp_string.cc:20:3: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
1 warning generated.
main.cc:26:26: warning: unused variable 'key' [-Wunused-variable]
main.cc:27:26: warning: unused variable 'val' [-Wunused-variable]
2 warnings generated. After$ sudo make clean
$ sudo make 2>&1 | grep "warning"
clang: warning: -framework IOKit: 'linker' input unused [-Wunused-command-line-argument]
smctemp.cc:61:1: warning: 'OSSpinLock' is deprecated: first deprecated in macOS 10.12 - Use os_unfair_lock() from <os/lock.h> instead [-Wdeprecated-declarations]
smctemp.cc:153:3: warning: 'IOMasterPort' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
smctemp.cc:214:3: warning: 'OSSpinLockLock' is deprecated: first deprecated in macOS 10.12 - Use os_unfair_lock_lock() from <os/lock.h> instead [-Wdeprecated-declarations]
smctemp.cc:242:3: warning: 'OSSpinLockUnlock' is deprecated: first deprecated in macOS 10.12 - Use os_unfair_lock_unlock() from <os/lock.h> instead [-Wdeprecated-declarations]
smctemp.cc:326:24: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
5 warnings generated.
clang: warning: -framework IOKit: 'linker' input unused [-Wunused-command-line-argument] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
smctemp::UInt32Char_t key = { 0 }; | ||
smctemp::SmcVal_t val; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note:
main.cc:26:26: warning: unused variable 'key' [-Wunused-variable]
main.cc:27:26: warning: unused variable 'val' [-Wunused-variable]
memset(&inputStructure, 0, sizeof(SmcKeyData_t)); | ||
memset(&outputStructure, 0, sizeof(SmcKeyData_t)); | ||
memset(&val, 0, sizeof(SmcVal_t)); | ||
|
||
inputStructure.key = string_util::strtoul(key, 4, 16); | ||
sprintf(val.key, key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note:
smctemp.cc:326:3: warning: 'sprintf' is deprecated:
This function is provided for compatibility reasons only.
Due to security concerns inherent in the design of sprintf(3),
it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
smctemp.cc
Outdated
memset(&inputStructure, 0, sizeof(SmcKeyData_t)); | ||
memset(&outputStructure, 0, sizeof(SmcKeyData_t)); | ||
memset(&val, 0, sizeof(SmcVal_t)); | ||
|
||
inputStructure.key = string_util::strtoul(key, 4, 16); | ||
sprintf(val.key, key); | ||
|
||
snprintf(val.key, 5, key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf(val.key, 5, key); | |
snprintf(val.key, sizeof(val.key), key); |
Could you use sizeof
in second argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
- prevent incorrect typecasting (comparison between signed and unsigned) - prevent buffer overflows by replacing sprintf with snprintf - remove unused variables - newline added in final output - add *.swp to gitignore - whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! LGTM
Fix compile-time warnings and other nits